define([
    'app',
    'underscore'
], function(app, _) {
    app.controller('CodeGeneratorController', function Controller() {
        var that = this;
        
        that.params = {
            parameters: '{ "greeting": "Hello, World !" }',
            template: 'Greet to all: <%=greeting%>'
        };
        that.generatedCode = '';

        that.init = function() {
            new Clipboard('#copy');
        };

        that.generateCode = function(valid) {
            if (valid) {
                var parameters = angular.fromJson(that.params.parameters);
                var template = _.template(that.params.template);
                that.generatedCode = template(parameters);
            }
        };
        
        that.clearAll = function() {
            that.params = {
                parameters: '',
                template: ''
            };
            that.generatedCode = '';
        };
    });
});
